<template>
    <div class="app-container">
        <div class="filter-container">
          <!--  <el-select v-model="params.countyKey" class="filter-item" @keyup.enter.native="fetchData"
                       style="margin-right: 20px;" placeholder="所属县域" v-if="localCode==0">
                <el-option   v-for="item in optionsTown"
                             :key="item.listKey"
                             :label="item.listValue"
                             :value="item.listKey"/>
            </el-select>-->
            <el-input v-model="params.name" placeholder="企业名称" style="width: 200px;" class="filter-item"
                      @keyup.enter.native="fetchData" clearable/>

            <el-input v-model="params.message" placeholder="内容" style="width: 200px;margin-left: 20px;" class="filter-item"
                      @keyup.enter.native="fetchData" clearable/>

            <el-select v-model="params.type" class="filter-item" @keyup.enter.native="fetchData" style="margin-left: 20px;" placeholder="业务名称">
                <el-option key="0" :label="item" :value="index" v-for="(item,index) in logType" :key="index"/>
            </el-select>

            <el-button v-waves class="filter-item input-margin" type="primary" icon="el-icon-search" @click="fetchData">
                搜索
            </el-button>
            <el-button @click="resetForm()"  type="success" icon="el-icon-warning-outline"  class="filter-item">重置</el-button>

        </div>

        <el-table
                v-loading="listLoading"
                :data="list"

                element-loading-text="Loading"
                border
                fit
                highlight-current-row
        >
         <!--   <el-table-column label="所属县域" v-if="localCode==0">
                <template slot-scope="scope">
                    {{ scope.row.countyName }}
                </template>
            </el-table-column>-->
            <el-table-column label="企业名称">
                <template slot-scope="scope">
                    {{ scope.row.entNameCn }}
                </template>
            </el-table-column>

            <el-table-column label="内容">
                <template slot-scope="scope">
                    {{ scope.row.message }}
                </template>
            </el-table-column>
            <el-table-column label="业务名称" align="center">
                <template slot-scope="scope">
                    {{ scope.row.operation|operationLogTypeFilter }}
                </template>
            </el-table-column>
            <el-table-column label="操作用户" align="center">
                <template slot-scope="scope">
                    {{ scope.row.createUser }}
                </template>
            </el-table-column>
            <el-table-column label="操作时间" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.createTime }}</span>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="params.page" :limit.sync="params.pageSize"
                    @pagination="fetchData"/>


    </div>
</template>

<script>
  import { getList, getLogType,prefixLogList } from '@/api/log'
  import Pagination from '@/components/Pagination'
  import waves from '@/directive/waves'
  import {operationLogType} from '@/utils/constant'
  import { userInfo,getAddress } from '@/api/user'
  export default {
    filters:{
      operationLogTypeFilter(type){
        return operationLogType[type];
      }
    },
    components: { Pagination },
    directives: { waves },
    data() {
      return {
        list: null,
        listLoading: true,
        total: 10,
          localCode:null,
          optionsTown:[],
        logType: operationLogType,
        params: {
          page: 1,
          pageSize: 10,
          name: '',
          message: ''
        }
      }
    },
    created() {
      this.fetchData();
        // this.getAddressData();
        // this.getUserInfo();
    },
    methods: {

      fetchData() {
        this.listLoading = true
          getList(this.params).then(response => {
          this.total = response.total
          this.list = response.rows
          this.listLoading = false
        })
      },
        getUserInfo(){
            userInfo().then((res)=>{
                if(res.locationCode=='' || res.locationCode==null){
                    this.localCode=0;
                }else{
                    this.localCode=1;
                }

            })
        },
        getAddressData(){
            getAddress().then((res)=>{

                this.optionsTown=res;
            })
        },
      resetForm() {
        this.params = {
          page: 1,
          pageSize: 10,
          name: '',
          message: ''
        }
        this.$nextTick(() => {
          this.fetchData()
          this.fetchType()
        })
      }
    }
  }
</script>
